package com.wwwarehouse.financialcenter.fragment.moneywarehouse.bankcard;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.text.TextUtils;
import android.view.View;
import android.view.animation.Animation;

import com.alibaba.fastjson.JSON;
import com.wwwarehouse.common.bean.response.CommonClass;
import com.wwwarehouse.common.custom_widget.SpaceItemDecoration;
import com.wwwarehouse.common.tools.ConvertUtils;
import com.wwwarehouse.financialcenter.R;
import com.wwwarehouse.financialcenter.adapter.moneyhouse.CardListAdapter;
import com.wwwarehouse.financialcenter.bean.bindingcard.BindCardBean;
import com.wwwarehouse.financialcenter.constant.FinancialConstant;
import com.wwwarehouse.financialcenter.fragment.base.TheParentFragment;

import java.util.HashMap;
import java.util.Map;

/**
 * Description:
 * Copyright  : Copyright (c) 2017
 * Author     : yfwang
 * Date       : 2017/11/13 16:36
 */
public class BindBankCardListFragment extends TheParentFragment {

    private RecyclerView mRecyclerView;

    @Override
    protected int getContentId() {
        return R.layout.financial_center_fragment_bindcard_list;
    }
    @Override
    public Animation onCreateAnimation(int transit, boolean enter, int nextAnim) {
        return null;
    }
    @Override
    protected void init(View view) {
        mRecyclerView = findView(view, R.id.rv_content);
        Bundle bundle = getArguments();
        mRecyclerView.addItemDecoration(new SpaceItemDecoration(ConvertUtils.dip2px(mActivity, 7), ConvertUtils.dip2px(mActivity, 7)));
        mRecyclerView.setLayoutManager(new LinearLayoutManager(mActivity) {
            @Override
            public boolean canScrollHorizontally() {
                return false;
            }

            @Override
            public boolean canScrollVertically() {
                return false;
            }

        });
        if (bundle!=null){
            String businessId = bundle.getString("businessId");
            int pos = bundle.getInt("pos");
            int num = bundle.getInt("num");
            Map<String,Object> map = new HashMap<>();
            Map<String,Object> query = new HashMap<>();
            map.put("businessId",businessId);
            query.put("page",pos+1);
            query.put("size",num);
            map.put("query",query);
            httpPost(FinancialConstant.GETS_BINDING_BANKCARD, map, 0, false, "");
        }
    }

    @Override
    public void onSuccess(CommonClass commonClass, int what) {
        if (what == 0) {
            if (TextUtils.equals("0", commonClass.getCode())) {
                BindCardBean.DataBean dataBeen = JSON.parseObject(commonClass.getData().toString(), BindCardBean.DataBean.class);
                CardListAdapter cardListAdapter = new CardListAdapter(mActivity,dataBeen.getList());
                mRecyclerView.setAdapter(cardListAdapter);
            }
        }
    }

    @Override
    public void onReLoad(int code) {

    }
}
